from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-09-06 14:05:32.737032
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 06, Sep, 2022
Time: 14:05:38
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.3374
Nobs: 771.000 HQIC: -50.6712
Log likelihood: 9858.20 FPE: 8.00072e-23
AIC: -50.8799 Det(Omega_mle): 7.12458e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299463 0.054427 5.502 0.000
L1.Burgenland 0.106488 0.036241 2.938 0.003
L1.Kärnten -0.106792 0.019257 -5.546 0.000
L1.Niederösterreich 0.205715 0.075830 2.713 0.007
L1.Oberösterreich 0.114190 0.073402 1.556 0.120
L1.Salzburg 0.253325 0.038783 6.532 0.000
L1.Steiermark 0.036158 0.050566 0.715 0.475
L1.Tirol 0.106863 0.040968 2.608 0.009
L1.Vorarlberg -0.060724 0.035229 -1.724 0.085
L1.Wien 0.050062 0.065213 0.768 0.443
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059513 0.113039 0.526 0.599
L1.Burgenland -0.034357 0.075268 -0.456 0.648
L1.Kärnten 0.047376 0.039994 1.185 0.236
L1.Niederösterreich -0.176554 0.157490 -1.121 0.262
L1.Oberösterreich 0.395055 0.152449 2.591 0.010
L1.Salzburg 0.290056 0.080547 3.601 0.000
L1.Steiermark 0.106045 0.105019 1.010 0.313
L1.Tirol 0.314460 0.085086 3.696 0.000
L1.Vorarlberg 0.027223 0.073166 0.372 0.710
L1.Wien -0.021631 0.135440 -0.160 0.873
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191695 0.027985 6.850 0.000
L1.Burgenland 0.089449 0.018634 4.800 0.000
L1.Kärnten -0.008409 0.009901 -0.849 0.396
L1.Niederösterreich 0.260995 0.038990 6.694 0.000
L1.Oberösterreich 0.133515 0.037742 3.538 0.000
L1.Salzburg 0.046325 0.019941 2.323 0.020
L1.Steiermark 0.018577 0.026000 0.714 0.475
L1.Tirol 0.092976 0.021065 4.414 0.000
L1.Vorarlberg 0.058424 0.018114 3.225 0.001
L1.Wien 0.117508 0.033531 3.504 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.108338 0.028441 3.809 0.000
L1.Burgenland 0.047404 0.018938 2.503 0.012
L1.Kärnten -0.014854 0.010063 -1.476 0.140
L1.Niederösterreich 0.191681 0.039624 4.837 0.000
L1.Oberösterreich 0.290065 0.038356 7.562 0.000
L1.Salzburg 0.111572 0.020266 5.505 0.000
L1.Steiermark 0.102895 0.026423 3.894 0.000
L1.Tirol 0.110511 0.021408 5.162 0.000
L1.Vorarlberg 0.069695 0.018409 3.786 0.000
L1.Wien -0.018029 0.034077 -0.529 0.597
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130906 0.051648 2.535 0.011
L1.Burgenland -0.050827 0.034390 -1.478 0.139
L1.Kärnten -0.040246 0.018273 -2.202 0.028
L1.Niederösterreich 0.170099 0.071957 2.364 0.018
L1.Oberösterreich 0.139330 0.069654 2.000 0.045
L1.Salzburg 0.287715 0.036802 7.818 0.000
L1.Steiermark 0.033745 0.047983 0.703 0.482
L1.Tirol 0.161740 0.038876 4.160 0.000
L1.Vorarlberg 0.100777 0.033430 3.015 0.003
L1.Wien 0.068628 0.061882 1.109 0.267
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056155 0.041109 1.366 0.172
L1.Burgenland 0.040299 0.027373 1.472 0.141
L1.Kärnten 0.050589 0.014545 3.478 0.001
L1.Niederösterreich 0.220898 0.057274 3.857 0.000
L1.Oberösterreich 0.282425 0.055441 5.094 0.000
L1.Salzburg 0.045575 0.029292 1.556 0.120
L1.Steiermark -0.000439 0.038192 -0.011 0.991
L1.Tirol 0.147807 0.030943 4.777 0.000
L1.Vorarlberg 0.073003 0.026608 2.744 0.006
L1.Wien 0.084453 0.049255 1.715 0.086
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180025 0.049231 3.657 0.000
L1.Burgenland -0.006199 0.032781 -0.189 0.850
L1.Kärnten -0.061276 0.017418 -3.518 0.000
L1.Niederösterreich -0.083797 0.068590 -1.222 0.222
L1.Oberösterreich 0.195757 0.066395 2.948 0.003
L1.Salzburg 0.056790 0.035080 1.619 0.105
L1.Steiermark 0.231494 0.045738 5.061 0.000
L1.Tirol 0.493809 0.037057 13.326 0.000
L1.Vorarlberg 0.048127 0.031865 1.510 0.131
L1.Wien -0.052614 0.058987 -0.892 0.372
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.166169 0.056509 2.941 0.003
L1.Burgenland -0.010237 0.037627 -0.272 0.786
L1.Kärnten 0.067133 0.019993 3.358 0.001
L1.Niederösterreich 0.206292 0.078730 2.620 0.009
L1.Oberösterreich -0.071036 0.076210 -0.932 0.351
L1.Salzburg 0.211500 0.040266 5.253 0.000
L1.Steiermark 0.115711 0.052500 2.204 0.028
L1.Tirol 0.071952 0.042535 1.692 0.091
L1.Vorarlberg 0.121622 0.036576 3.325 0.001
L1.Wien 0.122470 0.067707 1.809 0.070
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.357723 0.032685 10.944 0.000
L1.Burgenland 0.005350 0.021764 0.246 0.806
L1.Kärnten -0.023330 0.011564 -2.017 0.044
L1.Niederösterreich 0.214837 0.045538 4.718 0.000
L1.Oberösterreich 0.188048 0.044081 4.266 0.000
L1.Salzburg 0.046260 0.023290 1.986 0.047
L1.Steiermark -0.015640 0.030366 -0.515 0.607
L1.Tirol 0.106523 0.024603 4.330 0.000
L1.Vorarlberg 0.073558 0.021156 3.477 0.001
L1.Wien 0.048045 0.039162 1.227 0.220
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040023 0.148903 0.192407 0.157190 0.124702 0.113493 0.066015 0.222441
Kärnten 0.040023 1.000000 -0.004023 0.132538 0.041627 0.095724 0.430613 -0.052276 0.100274
Niederösterreich 0.148903 -0.004023 1.000000 0.338000 0.151972 0.298569 0.108591 0.183369 0.323909
Oberösterreich 0.192407 0.132538 0.338000 1.000000 0.228809 0.330635 0.173084 0.167903 0.265188
Salzburg 0.157190 0.041627 0.151972 0.228809 1.000000 0.147889 0.122608 0.147435 0.133535
Steiermark 0.124702 0.095724 0.298569 0.330635 0.147889 1.000000 0.151668 0.138615 0.079643
Tirol 0.113493 0.430613 0.108591 0.173084 0.122608 0.151668 1.000000 0.115108 0.153608
Vorarlberg 0.066015 -0.052276 0.183369 0.167903 0.147435 0.138615 0.115108 1.000000 0.006791
Wien 0.222441 0.100274 0.323909 0.265188 0.133535 0.079643 0.153608 0.006791 1.000000